<template>
    <div class="loginldBox" v-loading.fullscreen.lock="loading" element-loading-text="登录中..." element-loading-background="rgba(0,0,0,.1)">
      
    </div>
</template>
  
<script setup>
    import { ref } from "vue";
    import {useRouter,useRoute} from 'vue-router'
    import {useUserStore} from '@/pinia/modules/user'
    import {getUserInfo} from '@/api/user'

    const router = useRouter()
    const route = useRoute()
    const userStore = useUserStore()

    const loading = ref(true)
    let token = route.query.cas_token || ''
    console.log("token:",token)
    if(token){
      userStore.setToken(token)
      // 获取用户信息
      getUserInfo().then(res =>{
          if(res.code == 200){
              userStore.setUserInfo({
                nickName:res.data.realName,
                loginTime:new Date(),
                realName:res.data.realName,
                company:res.data.company,
                permissionUserList:res.data.permissionUserList,// 权限数组
              })
              userStore.setDefaultRouterObject({
                defaultRouter:'Index',
                defaultRouterName:'首页'
              })
              //addRouter()
              router.push({name:userStore.defaultRouterObject.defaultRouter})
          }else{
            router.push(`/login_error?error_info=${res.message || ''}`)
          }
      }) 
    }else{
      router.push(`/login_error?error_info=登录错误`)
    }
    
</script>
  
<style lang="scss" scoped>
      
</style>
  